package ro.sergiu.finder.utils;

import javax.swing.DefaultComboBoxModel;
import ro.sergiu.finder.models.property.ComboAdapter;

/**
 *
 * @author Toporjinschi
 */
public class ComboEnumModel extends DefaultComboBoxModel {

    public ComboEnumModel(Class<? extends ComboAdapter> enumClass) {
        if (!enumClass.isEnum()) {
            return;
        }
        ComboAdapter[] enums = enumClass.getEnumConstants();
        if (enums == null) {
            return;
        }
        for (ComboAdapter item : enums) {
            this.addElement(item);
//            throw new RuntimeException("ss");
        }
    }

    @Override
    public ComboAdapter getElementAt(int index) {
        return (ComboAdapter) super.getElementAt(index);
    }

    @Override
    public ComboAdapter getSelectedItem() {
        return (ComboAdapter) super.getSelectedItem();
    }

}
